package hu.mapro.gwtui.server.data;

import hu.mapro.model.LongId;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.BeanUtils;

public class LongIdLocator extends com.google.web.bindery.requestfactory.shared.Locator<LongId, Long> {

	@PersistenceContext(unitName="persistenceUnitMapro")
	EntityManager entityManager;
	
	@Override
	public LongId create(Class<? extends LongId> clazz) {
		return BeanUtils.instantiate(clazz);
	}

	@Override
	public LongId find(Class<? extends LongId> clazz, Long id) {
		return entityManager.find(clazz, id);
	}

	@Override
	public Class<LongId> getDomainType() {
		return null;
	}

	@Override
	public Long getId(LongId domainObject) {
		return domainObject.getId();
	}

	@Override
	public Class<Long> getIdType() {
		return Long.class;
	}

	@Override
	public Object getVersion(LongId domainObject) {
		return domainObject.getVersion();
	}

}
